//! Copyright 2012 Virtium Technology, Inc.
//! All rights reserved
//!
#include "SysTick.h"

#if defined (__FW_BUILD__)
extern "C"  {
#include "stm32f10x.h"

    volatile U32 s_TickCnt;
    void SysTick_Handler(void)
    {
        s_TickCnt++;
    }
};
#else
    volatile U32 cSysTick::s_TickCnt;
#endif

void cSysTick::InitReset()
{
    #if defined (__FW_BUILD__)
    SysTick_Config(SystemCoreClock / 1000);     //tick interrupt is 1ms
    #endif
    s_TickCnt = 0;
}

bool cSysTick::CheckTimeOut()
{
    U32 timeBase = mTimeBase + mTimeout;

    if (mTimeBase > timeBase)
    {
        if ((mTimeBase > s_TickCnt) && (timeBase <= s_TickCnt))
        {
            return (true);
        }
    }
    else
    {
        if ((timeBase <= s_TickCnt) || (mTimeBase > s_TickCnt))
        {
            return (true);
        }
    }
    return (false);
}

